﻿using System;
using System.Collections.Generic;
using IllusionUtility.GetUtility;
using Manager;
using UnityEngine;

// Token: 0x0200025B RID: 603
public class BustNormal
{
	// Token: 0x06000E2D RID: 3629 RVA: 0x00063FD0 File Offset: 0x000621D0
	public virtual bool Init(GameObject objTarg, string assetBundleName, string assetName, string manifest)
	{
		this.InitEnd = false;
		this.normal = global::CommonLib.LoadAsset<global::NormalData>(assetBundleName, assetName, true, manifest);
		if (null == this.normal)
		{
			return false;
		}
		global::Singleton<Manager.Character>.Instance.AddLoadAssetBundle(assetBundleName);
		this.dictNormal.Clear();
		this.dictSmr.Clear();
		for (int i = 0; i < this.normal.data.Count; i++)
		{
			GameObject gameObject = objTarg.transform.FindLoop(this.normal.data[i].ObjectName);
			if (!(null == gameObject))
			{
				SkinnedMeshRenderer component = gameObject.GetComponent<SkinnedMeshRenderer>();
				if (!(null == component))
				{
					this.dictSmr[gameObject] = component;
					if (this.dictSmr[gameObject] && this.dictSmr[gameObject].sharedMesh)
					{
						Mesh mesh = UnityEngine.Object.Instantiate<Mesh>(this.dictSmr[gameObject].sharedMesh);
						mesh.name = this.dictSmr[gameObject].sharedMesh.name;
						this.dictSmr[gameObject].sharedMesh = mesh;
					}
					this.dictNormal[gameObject] = this.normal.data[i];
					Vector3[] value = new Vector3[this.normal.data[i].NormalMin.Count];
					this.dictCalc[gameObject] = value;
				}
			}
		}
		this.CheckNormals(assetName);
		if (this.dictNormal.Count != 0)
		{
			this.InitEnd = true;
		}
		global::AssetBundleManager.UnloadAssetBundle(assetBundleName, true, null);
		return this.InitEnd;
	}

	// Token: 0x06000E2E RID: 3630 RVA: 0x00064190 File Offset: 0x00062390
	public virtual void Release()
	{
		this.InitEnd = false;
		this.normal = null;
		this.dictNormal.Clear();
	}

	// Token: 0x06000E2F RID: 3631 RVA: 0x000641AC File Offset: 0x000623AC
	public virtual void CheckNormals(string assetName)
	{
		if (this.dictNormal == null)
		{
			return;
		}
		foreach (KeyValuePair<GameObject, global::NormalData.Param> keyValuePair in this.dictNormal)
		{
			if (keyValuePair.Value.NormalMin.Count != keyValuePair.Value.NormalMax.Count)
			{
			}
		}
	}

	// Token: 0x06000E30 RID: 3632 RVA: 0x00064238 File Offset: 0x00062438
	public virtual void Blend(float rate)
	{
		if (!this.InitEnd)
		{
			return;
		}
		foreach (KeyValuePair<GameObject, global::NormalData.Param> keyValuePair in this.dictNormal)
		{
			if (keyValuePair.Value.NormalMin.Count == keyValuePair.Value.NormalMax.Count)
			{
				for (int i = 0; i < keyValuePair.Value.NormalMin.Count; i++)
				{
					this.dictCalc[keyValuePair.Key][i] = Vector3.Lerp(keyValuePair.Value.NormalMin[i], keyValuePair.Value.NormalMax[i], rate);
				}
				this.dictSmr[keyValuePair.Key].sharedMesh.normals = this.dictCalc[keyValuePair.Key];
			}
		}
	}

	// Token: 0x04000F14 RID: 3860
	protected bool InitEnd;

	// Token: 0x04000F15 RID: 3861
	protected global::NormalData normal;

	// Token: 0x04000F16 RID: 3862
	protected Dictionary<GameObject, global::NormalData.Param> dictNormal = new Dictionary<GameObject, global::NormalData.Param>();

	// Token: 0x04000F17 RID: 3863
	protected Dictionary<GameObject, SkinnedMeshRenderer> dictSmr = new Dictionary<GameObject, SkinnedMeshRenderer>();

	// Token: 0x04000F18 RID: 3864
	protected Dictionary<GameObject, Vector3[]> dictCalc = new Dictionary<GameObject, Vector3[]>();
}
